package com.Algorithm.DynamicProgramming.LCS问题;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/04/13/13:49
 * @Description:
 * @Target:
 */
public class 最长连续公共子序列_暴力枚举 {
    // asdfghjkl
    // 6sasdfghgbtv


    public static void main(String[] args) {
        String ss1 = "addbbccaacbddbbb";
        String ss2 = "ddcddcbcdbcbbbdabdcddabddcadbbbbdddabacaadcdcaacd";
//  获取最长连续子序列


        dp(ss1,ss2);
       System.out.println(max);

//        System.out.println(dp(ss1,ss2,0,0));
    }

    // 如果在长的里面，从每个元素开始，都遍历短的。。。
    static int max;
    // 获取最长连续子序列
    static void dp(String ss1,String ss2){
        // index1 指的是ss1的
        char[] chars1 = ss1.toCharArray();
        char[] chars2 = ss2.toCharArray();
        
        int[][] LCS = new int[chars1.length+1][chars2.length+1];

        for (int i = 0; i < LCS.length-1; i++) {
            for (int j = 0; j < LCS[0].length-1; j++) {
                if (chars1[i] == chars2[j]){
                    LCS[i+1][j+1] =  LCS[i][j]+1; 
                    max = Math.max(LCS[i+1][j+1],max);
                }else{
                    LCS[i+1][j+1] = 0;
                }
            }
        }

        for (int i = 0; i < LCS.length-1; i++) {
            for (int j = 0; j < LCS[0].length-1; j++) {
                System.out.print(LCS[i][j]+" ");
            }
            System.out.println();
        }
        
        

    }







}
